package com.deguru.main.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.deguru.main.dto.User;
import com.deguru.main.service.UserService;
import com.deguru.main.utils.SqlSessTools;

public class UserServiceImpl extends SqlSessTools implements UserService {

	List<User> users = null;
	
	@Override
	public User selectByUserIdAndPassword(String userId, String pswd) {
		Map<String, Object> user = new HashMap<String, Object>();
		user.put("userId", userId);
		user.put("passWord", pswd);
		SqlSession sqlSession = getSs();
		users = sqlSession.selectList("com.deguru.main.dao.UserMapper.selectByUserIdAndPassword", user);
		ssClose();
		return users.size()>0?users.get(0):null;
	}

	@Override
	public boolean selectByUserId(String userId) {
		
		SqlSession sqlSession = getSs();
		users = sqlSession.selectList("com.deguru.main.dao.UserMapper.selectByUserId", userId);
		ssClose();
		
		return users.size()>0?true:false;
	}

	@Override
	public int insertNewUser(User user) {

		SqlSession sqlSession = getSs();
		int count = 0;
		count = sqlSession.insert("com.deguru.main.dao.UserMapper.insertSelective", user);
		ssClose();
		
		return count;
	}

}
